﻿namespace System.Lua.Converters
{
    internal class BooleanConverter : LuaTypeConverter<System.ComponentModel.BooleanConverter>
    {
        private const string True = "true";
        private const string False = "false";

        public override object ConvertTo(object value, Type targetType)
        {
            if (value == null)
                throw new ArgumentNullException("value");
            if (value.GetType() != typeof(Boolean))
                throw new ArgumentException("Value type mismatch", "value");

            if (targetType == typeof(string))
                return ((bool)value) ? True : False;

            return base.ConvertTo(value, targetType);
        }

        /// <summary>
        /// Gets a value indicating whether the string returned by the convert is a valid Lua
        /// literal.
        /// </summary>
        public override bool ReturnsLiteral
        {
            get { return true; }
        }
    }
}